<template>
  <div style="background: #fff; padding: 30px">
    <div class="Title">{{ state.siteName }}站点</div>
    <div class="flewbtn">
      <!-- <el-select
        v-model="state.siteTypeVal"
        placeholder="展具类型"
        class="elSelect_a"
        size="large"
      >
        <el-option
          v-for="item in state.options"
          :key="item.value"
          :label="item.label"
          :value="item.value"
          :popper-append-to-body="false"
        />
      </el-select>
      <el-select
        v-model="state.siteLevel"
        placeholder="展具级别"
        class="elSelect_a"
        size="large"
      >
        <el-option
          v-for="item in state.optionsTwo"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select> -->
      <el-select
        v-model="state.yearLevel"
        placeholder="选择年份"
        class="elSelect_a" 
        size="large"
      >
        <el-option
          v-for="item in state.yearList"
          :key="item.value"
          :label="item.label"
          :value="item.value"
        />
      </el-select>
      <el-button size="large" type="primary" @click="checkSiteList"
        >查询</el-button
      >
      <!-- <el-button size="large" @click="clearSite">清除</el-button> -->
      <el-button size="large" @click="addSite">增加</el-button>
      <el-button size="large" @click="reportExport">报告导出</el-button>
    </div>
    <!-- 展示和编辑表格 -->
    <el-scrollbar style="margin-bottom: 20px" height="650px">
      <el-table
        :data="filterTableData"
        :header-cell-style="{
          'text-align': 'center',
          background: '#f2f3f5',
          height: '50px',
          color: '#000000',
          'font-size': '15px',
        }"
        :cell-style="{ 'text-align': 'center' }"
        style="width: 100%"
        height="620"
        ref="multipleTableRef"
        @selection-change="handleSelectionChange"
      >
        <el-table-column type="selection" width="55" />
        <el-table-column label="站点名称" prop="siteTitle" width="220" />
        <!-- <el-table-column label="站点LOGO" prop="siteTime" width="220" /> -->
        <el-table-column label="站点LOGO" prop="logo" width="250">
          <template v-slot="scope">
            <!-- <img :src="scope.row.plan" min-width="70" height="70" /> -->
            <el-image
              style="width: 120px; height: 90px; border-radius: 10px"
              preview-teleported="true"
              :preview-src-list="scope.row.logo_a"
              :src="scope.row.logo"
              fit="contain"
            />
          </template>
        </el-table-column>
        <el-table-column label="店端名称" prop="exhibition" width="220" />
        <el-table-column label="预计发货时间" prop="buildtime1" width="220" />
        <el-table-column label="预计到货时间" prop="buildtime2" width="220" />
        <el-table-column label="展会开始时间" prop="ext_starttime" width="220" />
        <el-table-column label="展会结束时间" prop="ext_endtime" width="220" />
        <!-- <el-table-column label="撤展开始时间" prop="finishtime1" width="220" />
        <el-table-column label="站点结束时间" prop="finishtime2" width="220" /> -->
        <el-table-column label="城市" prop="city" width="180" />
        <el-table-column label="省份" prop="province" width="220" />
        <el-table-column label="店端平面图" prop="positionimage" width="250">
          <template v-slot="scope">
            <!-- <img :src="scope.row.plan" min-width="70" height="70" /> -->
            <el-image
              style="width: 120px; height: 90px; border-radius: 10px"
              preview-teleported="true"
              :preview-src-list="scope.row.positionimage_a"
              :src="scope.row.positionimage"
              fit="cover"
            />
          </template>
        </el-table-column>
        <el-table-column label="联系人" prop="positionnum" width="180" />
        <el-table-column label="联系电话" prop="size" width="200" />
        <el-table-column label="送货地址" prop="heightlimit" width="200" />
        <el-table-column label="点位设计图" prop="designimage" width="250">
          <template v-slot="scope">
            <!-- <img :src="scope.row.designImg" min-width="70" height="70" /> -->
            <el-image
              style="width: 120px; height: 90px; border-radius: 10px"
              preview-teleported="true"
              :preview-src-list="scope.row.designimage_a"
              :src="scope.row.designimage"
              fit="cover"
            />
          </template>
        </el-table-column>
        <el-table-column label="物料号" prop="exhcar" width="220" />
        <el-table-column label="物料说明" prop="tracar" width="220" />
        <!-- 要做个下拉的显示列表 -->
        <!-- <el-table-column label="运营账号ID" prop="operator_id" width="220" /> -->
        <el-table-column label="运营账号ID" prop="operator_id" width="220">
          <template v-slot="scope">
            <el-dropdown>
              <span class="el-dropdown-link">
                {{ scope.row.operator_id[0]
                }}<el-icon class="el-icon--right"><arrow-down /></el-icon>
              </span>
              <template #dropdown>
                <el-dropdown-menu>
                  <el-dropdown-item
                    v-for="(item, index) in scope.row.operator_id"
                    :key="index"
                    >{{ item }}</el-dropdown-item
                  >
                </el-dropdown-menu>
              </template>
            </el-dropdown>
          </template>
        </el-table-column>
        <el-table-column label="现场负责人" prop="controller" width="220" />
        <!-- <el-table-column label="送货地址" prop="factory" width="220" /> -->
        <el-table-column label="备注说明" prop="activity_name" width="220" />
        <!-- <el-table-column
          label="展会开始时间"
          prop="ext_starttime"
          width="220"
        />
        <el-table-column label="展会结束时间" prop="ext_endtime" width="220" />
        <el-table-column label="运营开始时间" prop="starttime" width="220" />
        <el-table-column label="运营结束时间" prop="endtime" width="220" />
        <el-table-column label="运营日期" prop="time_between" width="220" /> -->
        <el-table-column label="状态" prop="stage" width="160" />
        <!-- 用户权限显示开始 -->
        <el-table-column prop="powerEditing" width="220">
           <template #header>
            <div>管理权限</div>
           </template>
           <template #default="scope">
            <el-button
              size="small"
              @click="handlePowerEdit(scope.$index, scope.row)"
              type="primary"
              text
              >权限编辑</el-button
            >
           </template>
        </el-table-column>
        <el-table-column align="right" width="220">
          <!-- <template #header>
                  <el-input v-model="search" size="small" placeholder="Type to search" />
                </template> -->
          <template #header>
            <div>操作</div>
          </template>
          <template #default="scope">
            <!-- <el-button size="small" @click="handleEdit(scope.$index, scope.row)">编辑</el-button> -->
            <el-button
              size="small"
              @click="handleEdit(scope.$index, scope.row)"
              type="primary"
              text
              >编辑</el-button
            >
            <!-- <el-button
              size="small"
              @click="handleDelete(scope.$index, scope.row)"
              type="primary"
              text
              >删除
            </el-button>
            <el-button
              size="small"
              @click="handleDelete(scope.$index, scope.row)"
              type="primary"
              text
              >刷新
            </el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </el-scrollbar>
    <!-- 分页显示 -->
    <el-pagination
      v-model:current-page="state.currentPage4"
      v-model:page-size="pageSize4"
      background
      page-sizes="10"
      :small="small"
      :disabled="disabled"
      layout="total, prev, pager, next"
      :total="state.total_a"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
      style="display: flex; justify-content: flex-end"
    />

    <!-- 编辑对话框 -->
    <el-dialog
      v-model="state.showModel"
      title="编辑项目"
      width="500px"
      align-center
      style="font-weight: 600"
    >
      <el-scrollbar height="600px">
        <div
          style="display: flex; justify-content: center; align-items: center"
        >
          <div class="siteAll">创建名称</div>
          <el-input
            v-model="state.createName"
            size="small"
            style="flex: 8"
            class="enterpriseName"
          />
        </div>
        <div style="display: flex; margin-top: 25px; margin-bottom: 25px">
          <div class="siteAll_h4">
            <div>站点</div>
            <div>LOGO</div>
          </div>
          <div>
            <el-upload
              v-model:file-list="state.uploadImgList_a"
              :http-request="selfUploadPic_a"
              action="upUrl"
              list-type="picture-card"
              :on-exceed="handleExceed_a"
              :on-preview="handlePictureCardPreview_a"
              :on-remove="handleRemove_a"
            >
              <el-icon><Plus /></el-icon>
            </el-upload>
            <el-dialog v-model="state.dialogVisible_a">
              <!-- <img w-full :src="state.dialogImageUrl" alt="Preview Image" /> -->
              <el-image :src="state.dialogImageUrl_a" :fit="contain" />
            </el-dialog>
            <div style="font-size: 10px; color: #b8b8b8; margin-top: 5px">
              {{ state.picTip }}
            </div>
          </div>
        </div>
        <div class="line_b1">工作流选择</div>
        <div style="display: flex; margin-top: 20px; margin-bottom: 20px">
          <div class="line_b"></div>
          <div class="line_f">
            <el-checkbox-group
              v-model="state.siteVest_f"
              fill="#409eff"
              @change="getworkLineItem"
            >
              <el-checkbox
                v-for="(item, index) in state.workLineList"
                :key="index"
                :label="item"
                name="siteVest_f"
              />
            </el-checkbox-group>
          </div>
        </div>
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_h3">路线选择</div>
          <el-select
            v-model="state.pathVal"
            class="elSelect"
            size="small"
            @change="getLineId"
          >
            <el-option
              v-for="item in state.mouldArr"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div>
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">预计发货时间</div>
          <el-date-picker
            v-model="state.buildtime1"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD HH:mm"
            value-format="YYYY/MM/DD HH:mm"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div>
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">预计到货时间</div>
          <el-date-picker
            v-model="state.buildtime2"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD HH:mm"
            value-format="YYYY/MM/DD HH:mm"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div>
        <!-- <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">撤展开始时间</div>
          <el-date-picker
            v-model="state.finishtime1"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD HH:mm"
            value-format="YYYY/MM/DD HH:mm"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div>
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">撤展结束时间</div>
          <el-date-picker
            v-model="state.finishtime2"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD HH:mm"
            value-format="YYYY/MM/DD HH:mm"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div> -->
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">展会开始时间</div>
          <el-date-picker
            v-model="state.ext_starttime"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD"
            value-format="YYYY/MM/DD"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div>
        <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a">展会结束时间</div>
          <el-date-picker
            v-model="state.ext_endtime"
            type="datetime"
            placeholder=""
            format="YYYY/MM/DD"
            value-format="YYYY/MM/DD"
            class="elSelect"
            style="width: 100%"
            size="small"
          />
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e2">店端名称</div>
          <el-input
            v-model="state.exhibition"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <!-- <div style="display: flex; margin-top: 15px">
          <div class="siteAll_a_1">推送时间</div>
          <el-time-select
            v-model="state.sent_time"
            start="01:00"
            step="00:30"
            end="24:00"
            class="elSelect"
            style="width: 100%"
            size="small"
            placeholder="请选择推送时间"
          />
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e2">推送邮箱</div>
          <el-input
            v-model="state.email_list"
            style="flex: 8"
            placeholder="推送多个邮箱请用英文逗号隔开"
            size="small"
            class="enterpriseName"
          />
        </div> -->
        <div class="siteAll_b" style="margin-top: 0px">
          <div class="siteAll_c">执行人</div>
          <el-input
            v-model="state.controller"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div style="display: flex">
          <div class="siteAll_h7">运营账号</div>
          <div class="siteAll_h6">
            <el-checkbox-group
              v-model="state.worktype"
              fill="#409eff"
              @change="getWorkName"
            >
              <el-checkbox
                v-for="(item, index) in state.usersName"
                :key="index"
                :label="item"
                name="worktype"
              />
            </el-checkbox-group>
          </div>
        </div>
        <div class="dialog-footer_a">
          <el-button size="small" @click="changeWorkList"> 刷新 </el-button>
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e1">城市</div>
          <el-input
            v-model="state.city"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e1">省份</div>
          <el-input
            v-model="state.province"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <!-- <div class="siteAll_d">
          <div class="siteAll_e2">送货地址</div>
          <el-input
            v-model="state.factory"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div> -->
        <div style="display: flex; margin-top: 18px; margin-bottom: 25px">
          <div class="siteAll_f">平面图</div>
          <div>
            <el-upload
              v-model:file-list="state.uploadImgList"
              :http-request="selfUploadPic"
              action="upUrl"
              list-type="picture-card"
              :limit="1"
              :on-exceed="handleExceed"
              :on-preview="handlePictureCardPreview"
              :on-remove="handleRemove"
            >
              <el-icon><Plus /></el-icon>
            </el-upload>
            <el-dialog v-model="state.dialogVisible">
              <!-- <img w-full :src="state.dialogImageUrl" alt="Preview Image" /> -->
              <el-image :src="state.dialogImageUrl" :fit="contain" />
            </el-dialog>
            <div style="font-size: 10px; color: #b8b8b8; margin-top: 5px">
              {{ state.picTip }}
            </div>
          </div>
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e">联系人</div>
          <el-input
            v-model="state.positionnum"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div class="siteAll_d">
          <div class="siteAll_e2">联系电话</div>
          <el-input
            v-model="state.size"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div class="siteAll_g">
          <div class="siteAll_h">送货地址</div>
          <el-input
            v-model="state.heightlimit"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <!-- 上传图片的这个逻辑还没写 -->
        <div style="display: flex; margin-top: 18px; margin-bottom: 25px">
          <div class="siteAll_f">设计图</div>
          <div>
            <el-upload
              v-model:file-list="state.uploadImgList_b"
              :http-request="selfUploadPic_b"
              action="upUrl"
              list-type="picture-card"
              :limit="1"
              :on-exceed="handleExceed_b"
              :on-preview="handlePictureCardPreview_b"
              :on-remove="handleRemove_b"
            >
              <el-icon><Plus /></el-icon>
            </el-upload>
            <el-dialog v-model="state.dialogVisible_b">
              <!-- <img w-full :src="state.dialogImageUrl" alt="Preview Image" /> -->
              <el-image :src="state.dialogImageUrl_b" :fit="contain" />
            </el-dialog>
            <div style="font-size: 10px; color: #b8b8b8; margin-top: 5px">
              {{ state.picTip }}
            </div>
          </div>
        </div>
        <!-- 选择展具 -->
        <!-- <div style="display: flex; margin-top: 15px">
          <div class="siteAll_h3">展具选择</div>
          <el-select
            v-model="state.toolVal"
            class="elSelect"
            size="small"
            @change="getToolId"
          >
            <el-option
              v-for="item in state.toolArr"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            />
          </el-select>
        </div> -->

        <div class="siteAll_d">
          <div class="siteAll_e">物料号</div>
          <el-input
            v-model="state.exhcar"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div class="siteAll_h1">
          <div class="siteAll_h5">物料说明</div>
          <el-input
            v-model="state.tracar"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <div class="siteAll_h1">
          <div class="siteAll_h5">备注说明</div>
          <el-input
            v-model="state.activity_name"
            style="flex: 8"
            size="small"
            class="enterpriseName"
          />
        </div>
        <!-- 通知复核员按钮 -->
        <!-- <div class="checkman">
          <el-button type="primary" @click="goNoticeInspect">通知复核员</el-button>
        </div> -->

        <!-- <div style="display: flex; margin-top: 0px">
          <div style="margin: 10px 8px 10px 27px; font-weight: 600">
            站点状态
          </div>
          <el-radio-group
            fill="#409eff"
            v-model="state.radioState"
            size="small"
          >
            <el-radio-button label="启用" />
            <el-radio-button label="停用" />
          </el-radio-group>
        </div> -->
        <div class="dialog-footer">
          <el-button size="small" @click="closeInput"> 取消 </el-button>
          <el-button type="primary" size="small" @click="startSubmit">
            确认
          </el-button>
        </div>
      </el-scrollbar>
    </el-dialog>
    <!-- 权限编辑对话框 -->
    <el-dialog
      v-model="state.showPowerModel"
      title="权限编辑"
      width="500px"
      align-center
      style="font-weight: 600"
    >
    <!-- <el-scrollbar height="600px"> -->
    <el-scrollbar>
        <!-- 账号权限开始 -->
        <div style="display: flex; margin-bottom: 8px">
          <div class="line_g_a">普通权限</div>
          <div class="siteAll_h6">
            <el-checkbox-group
              v-model="state.ordinarytype"
              fill="#409eff"
              @change="getordinaryName"
            >
              <el-checkbox
                v-for="(item, index) in state.usersName_a"
                :key="index"
                :label="item"
                name="ordinarytype"
              />
            </el-checkbox-group>
          </div>
        </div>
        <div style="display: flex; margin-bottom: 8px">
          <div class="line_g_a">项目简介审核</div>
          <div class="siteAll_h6">
            <el-checkbox-group
              v-model="state.managetype"
              fill="#409eff"
              @change="getmanageName"
            >
              <el-checkbox
                v-for="(item, index) in state.usersName_a"
                :key="index"
                :label="item"
                name="managetype"
              />
            </el-checkbox-group>
          </div>
        </div>

        <div style="display: flex; margin-bottom: 8px">
          <div class="line_g_a">工作流审核</div>
          <div class="siteAll_h6">
            <el-checkbox-group
              v-model="state.auditingtype"
              fill="#409eff"
              @change="getAuditingName"
            >
              <el-checkbox
                v-for="(item, index) in state.usersName_a"
                :key="index"
                :label="item"
                name="auditingtype"
              />
            </el-checkbox-group>
          </div>
        </div>

        <div style="display: flex; margin-bottom: 8px">
          <div class="line_g_a">客户权限</div>
          <div class="siteAll_h6">
            <el-checkbox-group
              v-model="state.customtype"
              fill="#409eff"
              @change="getcustomName"
            >
              <el-checkbox
                v-for="(item, index) in state.usersName_a"
                :key="index"
                :label="item"
                name="customtype"
              />
            </el-checkbox-group>
          </div>
        </div>
        <!-- <div class="dialog-footer_a">
          <el-button size="small" @click="changeWorkList"> 刷新 </el-button>
        </div> -->
        <div class="dialog-footer">
          <el-button size="small" @click="closePowerModel"> 取消 </el-button>
          <el-button type="primary" size="small" @click="submitFromPower">
            确认
          </el-button>
        </div>
        <!-- 结束 -->
    </el-scrollbar>
  </el-dialog>
  </div>
</template>
  
  <script setup>
import { toRefs, reactive, onMounted, computed, ref } from "vue";
import { useRoute } from "vue-router";
import { ArrowDown, Plus } from "@element-plus/icons-vue";
import http from "../libs/http";
var pageIdx = 1;
let addtableData = []    //新增的表格数据
var newworkList = []

const state = reactive({
  options: [
    {
      value: "展具物流到货",
      label: "展具物流到货",
    },
    {
      value: "卸货说明",
      label: "卸货说明",
    },
    {
      value: "立柱到位立正",
      label: "立柱到位立正",
    },
  ],
  optionsTwo: [
    {
      value: "B级",
      label: "B级",
    },
    {
      value: "C级",
      label: "C级",
    },
    {
      value: "E级",
      label: "E级",
    },
  ],
  yearList: [
    {
      value: "2023",
      label: "2023年",
    },
    {
      value: "2024",
      label: "2024年",
    },
  ],
  mouldArr: [],
  modelVal: "选择模板",
  tableData: [],
  showModel: false, //显示编辑弹窗
  picTip:
    "建议宽高比16:9 780*438<尺寸<2560*1440 格式:JPG/JPEG/PNG文件大小≤1000KB",
  vestVal: [],
  siteVest: [],
  siteTypeVal: "",
  siteLevel: "",
  yearLevel: "",   //站点分级
  //上传图片参数
  uploadImgList: [],
  uploadImgList_a: [],
  uploadImgList_b: [],
  dialogVisible: false,
  dialogVisible_a: false,
  dialogVisible_b: false,
  dialogImageUrl: "",
  dialogImageUrl_a: "",
  dialogImageUrl_b: "",

  // 页面接受的标题名称和ID
  siteName: "",
  sitetypeId: "",
  total: "", //总条数
  total_a: 0, 
  total_page: "", //总页数

  //运营人员名字和uid
  userList: "",
  usersName: [],
  userUid: [],
  new_nameUid: [],
  userTotal: "", //用户列表总条数
  userTotal_page: "", //用户列表总页数

  usersName_a: [],
  userUid_a: [],
  new_nameUid_a: [],
  userList_a: "",
  sid_s:'',
  showPowerModel: false,    //显示用户权限编辑框
  managetype: [], //管理
  manage_id: '',
  ordinarytype: [], //普通
  ordinary_id: '',
  auditingtype: [], //审核
  auditing_id: '',
  customtype: [],   //客户
  customt_id: '',

  // 需要提交的表单数据
  createName: "",
  logoImg: [], //logo图片
  pathVal: "", //路线名称
  pathValId: "", //路线Id
  buildtime1: "",
  buildtime2: "",
  finishtime1: "",
  finishtime2: "",
  ext_starttime: "",
  ext_endtime: "",
  factory: "",
  controller: "",
  sent_time: "22:00",    //推送邮箱时间
  email_list: "",  //拼接邮箱地址
  operator_id: "", //运营账号id,用，拼接成字符串
  city: "",
  province: "",
  exhibition: "",
  positionimage: [], //展位图片
  positionnum: "",
  size: "",
  heightlimit: "",
  designimage: [], //展具图
  exhcar: "",
  tracar: "",
  activity_name: "",
  radioState: "启用",

  nameVal: "",
  activeTime: "",
  numVal: "",
  planImg: "",
  limitVal: "",
  specsVal: "",
  siteLogoImg: "",
  worktype: [],

  // 展具参数
  toolVal: "",
  toolArr: [],
  toolSelVal: "",
  toolId: "",

  selectReportlist: "", //导出报告列表
  // 选择工作流
  siteVest_f: [],
  workLineList: [],
  workIdList: [],
  siteLineStr: "",

  // 当前分页页数
  currentPage4: 1
});

// 初始化数据
onMounted(() => {
  //接受路由传过来的参数
  const route = useRoute();
  // router.go(0)
  console.log("route接受到的参数>>>>>>>>>>>>>>>>", Number(route.query.id));
  state.sitetypeId = Number(route.query.id);
  state.siteName = route.query.name;
  state.total_a = Number(route.query.total) 
  getdevlists(state.sitetypeId)
  getLineList();
  getUserList();
  
  getWorkitemsList();

  getUserList_a()
  // state.yearLevel = localStorage.getItem("yearLevel") || ""
});

// 获取工作流列表
const getWorkitemsList = async () => {
  let param = {
    openid: localStorage.getItem("openid"),
  };
  const res = await http.$get("/apies/backend/getWorkitemsList", param);
  if (res.code == 200) {
    let workList = res.data
    let widList = []
    workList.map(i => {
      newworkList.push(i.name)
      widList.push(i.wid)
    })
    console.log(newworkList,'>>>>>>>>>>>>站点分级拿到工作流')
    console.log(widList,'>>>>>>>>>>>>拿到站点ID工作流工作流啦啦啦啦啦啦啦')
    state.workLineList = newworkList
    state.workIdList = widList

    setTimeout(() => {
      getSiteList(state.sitetypeId);
    },500)
  } else {
    console.log('>>>>>>>>>>获取工作列表数据失败了')
  }
}

// 获取选择工作流项
const getworkLineItem = (e) => {
  console.log("拿到选择的所有工作流了", e);
  let newWorkLine = [];
  state.workLineList.map((i, k) => {
    e.map((j, y) => {
      if (i == j) {
        newWorkLine.push(state.workIdList[k]);
      }
    });
  });
  console.log(
    newWorkLine.join(","),
    ">>>>>>>>>>>>>>>>>>>>拿到所有工作流下标了"
  );
  state.siteLineStr = newWorkLine.join(",");
};


// 渲染拿到展具列表
const getdevlists = async (siteId) => {
  let param = {
    openid: localStorage.getItem("openid"),
    sitetype: siteId
  };
  console.log('>>>>>>需要请求的参数展具', param)
  const res = await http.$get("/apies/backend/getdevlists", param);
  if (res.code == 200) {
    console.log(">>>>>>展具请求成功了", res.data)
    let allTool = [];
    res.data.map(i => {
      allTool.push({
        label: i.sn,
        value: i.id,
      })
    })
    state.toolArr = allTool
  } else {
    console.log('>>>>>>>>>>>>接口请求失败了')
  }
}
// 获取选中展具的值
const getToolId = (e) => {
  console.log('>>>>>>>>>>>>>>>拿到选中的展具值了', e)
  state.toolSelVal = e      //需要传给接口的值
  state.toolArr.map((i) => {
    if (e == i.value) {
      console.log(i.label);
      state.toolVal = i.label;  //需要显示的值
    }
  });
}


// 获取所有路线id和名称
const getLineList = async () => {
  let param = {
    openid: localStorage.getItem("openid"),
  };
  const res = await http.$get("/apies/backend/getLineList", param);
  if (res.code == 200) {
    let allLine = [];
    res.data.list.map((i) => {
      allLine.push({
        label: i.name,
        value: i.id,
      });
      state.mouldArr = allLine;
    });
  }
};
// 获取路线的id值
const getLineId = (e) => {
  state.pathValId = e;
  console.log(e, ">>>>>>>>>>>");
  state.mouldArr.map((i) => {
    if (e == i.value) {
      console.log(i.label);
      state.pathVal = i.label;
    }
  });
};

//拿到选中运营人员的值
const getWorkName = (e) => {
  console.log(
    ">>>>>>>>>>选中的工作人员",
    e,
    ">>>>>>>",
    JSON.parse(JSON.stringify(state.new_nameUid))
  );
  let strType = [];
  JSON.parse(JSON.stringify(state.new_nameUid)).map((i, j) => {
    e.map((j) => {
      if (j == i.name) {
        strType.push(i.id + "");
      }
    });
  });
  console.log(strType.join(","));
  state.operator_id = strType.join(",");
};

// 用户权限参数-------开始------
// 获取权限人员名字和Uid序号
const getUserList_a = async () => {
  let param = {
    openid: localStorage.getItem("openid"),
  };
  const res = await http.$get("/apies/backend/getRuleUserList", param);
  if (res.code == 200) {
    let new_userName_a = [];
    let new_userUid_a = [];
    let nameUid_a = [];
    // 有分页数据,要追加数据
    state.userList_a = res.data;
    res.data.map((i) => {
      new_userName_a.push(i.name);
      new_userUid_a.push(i.uid);
      nameUid_a.push({
        id: i.uid,
        name: i.name,
      });
    });
    state.usersName_a = new_userName_a;
    state.userUid_a = new_userUid_a;
    state.new_nameUid_a = nameUid_a;
  } else {
    console.log(">>>>获取用户列表失败");
  }
};

// 普通
const getordinaryName = (e) => {
  // console.log('>>>>>>>>>>>>选中管理人员', e, '>>>>>>>>>',JSON.parse(JSON.stringify(state.new_nameUid)))
  let strType_a = [];
  JSON.parse(JSON.stringify(state.new_nameUid_a)).map((i, j) => {
    e.map((j) => {
      if (j == i.name) {
        strType_a.push(i.id + "");
      }
    });
  });
  console.log(strType_a.join(","),'>>>>>>>>>>选中项');
  state.ordinary_id = strType_a.join(",")
};
// 项目简介审核
const getmanageName = (e) => {
  // console.log('>>>>>>>>>>>>选中管理人员', e, '>>>>>>>>>',JSON.parse(JSON.stringify(state.new_nameUid)))
  let strType_d = [];
  JSON.parse(JSON.stringify(state.new_nameUid_a)).map((i, j) => {
    e.map((j) => {
      if (j == i.name) {
        strType_d.push(i.id + "");
      }
    });
  });
  console.log(strType_d.join(","),'>>>>>>>>>>选中项');
  state.manage_id = strType_d.join(",")
};
// 审核
const getAuditingName = (e) => {
  // console.log('>>>>>>>>>>>>选中管理人员', e, '>>>>>>>>>',JSON.parse(JSON.stringify(state.new_nameUid)))
  let strType_b = [];
  JSON.parse(JSON.stringify(state.new_nameUid_a)).map((i, j) => {
    e.map((j) => {
      if (j == i.name) {
        strType_b.push(i.id + "");
      }
    });
  });
  console.log(strType_b.join(","),'>>>>>>>>>>选中项');
  state.auditing_id = strType_b.join(",")
}
// 客户
const getcustomName = (e) => {
  let strType_c = [];
  JSON.parse(JSON.stringify(state.new_nameUid_a)).map((i, j) => {
    e.map((j) => {
      if (j == i.name) {
        strType_c.push(i.id + "");
      }
    });
  });
  console.log(strType_c.join(","),'>>>>>>>>>>选中项');
  state.customt_id = strType_c.join(",")
}

// 新的管理权限表单逻辑
// 编辑
const handlePowerEdit = async (index, row) => {
  let rowList = JSON.parse(JSON.stringify(row))
  console.log('>>>>>>>>>>>>>>>>权限管理逻辑', rowList.sid)
  state.sid_s = rowList.sid
  let param = {
    openid: localStorage.getItem("openid"),
    sid: rowList.sid
  }
  // 获取以获得站点权限的数据
  const res = await http.$get("/apies/backend/getSiteRuleUserList", param);
  if(res.code == 200) {
    console.log('>>>>>>>>>>>>>拿到站点权限数据', res)
     // 这里是做回显数据用的
     let isPowerList = res.data.list
    let newLine_user = []; // 普通用户
    let newLine_check_project = []; // 项目简介审核
    let newLine_check = []; //工作流审查
    let newLine_customer = [];  //客户权限
    isPowerList.user.map((i, k) => {
      state.userUid_a.map((j, y)=> {
        if (Number(i) == j) {
          state.usersName_a.map((n, g) => {
            if (g == y) {
              newLine_user.push(n);
            }
          })
        }
      })
    })
    isPowerList.check_project.map((i, k) => {
      state.userUid_a.map((j, y)=> {
        if (Number(i) == j) {
          state.usersName_a.map((n, g) => {
            if (g == y) {
              newLine_check_project.push(n);
            }
          })
        }
      })
    })
    isPowerList.check.map((i, k) => {
      state.userUid_a.map((j, y)=> {
        if (Number(i) == j) {
          state.usersName_a.map((n, g) => {
            if (g == y) {
              newLine_check.push(n);
            }
          })
        }
      })
    })
    isPowerList.customer.map((i, k) => {
      state.userUid_a.map((j, y)=> {
        if (Number(i) == j) {
          state.usersName_a.map((n, g) => {
            if (g == y) {
              newLine_customer.push(n);
            }
          })
        }
      })
    })
    console.log('++++普通权限',newLine_user,'++++审核',newLine_check_project,newLine_check,'>>>>客户',newLine_customer,'拿到当前权限数据>>>>>>>>>>>>>>>>>>>>>>',isPowerList)
    console.log('>>>>>>>>数组转字符串',isPowerList.user.join(','))
    state.ordinarytype = newLine_user, //普通
    state.ordinary_id = isPowerList.user.join(','),
    state.managetype= newLine_check_project, //项目简介审核
    state.manage_id = isPowerList.check_project.join(','),
    state.auditingtype = newLine_check, //审核
    state.auditing_id = isPowerList.check.join(','),
    state.customtype = newLine_customer,   //客户
    state.customt_id = isPowerList.customer.join(','),

    state.showPowerModel = true
  } else {
    console.log('>>>>>>>>>>>>>>>>列表数据请求失败')
  }
}
// 取消
const closePowerModel = () => {
  console.log('>>>>>>>>>>>关闭表单了')
  state.showPowerModel = false
}
// 提交
const submitFromPower = async () => {
  let params = {
    openid: localStorage.getItem("openid"),
    sid: state.sid_s,
    user_list: state.ordinary_id,
    check_project_list: state.manage_id,
    check_list: state.auditing_id,
    customer_list: state.customt_id
  }
  console.log('>>>>>>>>>>>>>>>数据准备提交了,提交的数据', params)
  const res = await http.$post("/apies/backend/saveSiteUserRuleList", params);
  if (res.code == 200) {
    ElMessage({
          message: "编辑成功！",
          type: "success",
        })
    state.showPowerModel = false
  } else {
    ElMessage('编辑失败！')
  }
}


//通知复核员
const goNoticeInspect = () => {
  console.log('>>>>>>>>>>开始通知复核员了')
}

// -------结束-------

// 加载运营工作人员列表
const changeWorkList = async () => {
  console.log(
    ">>>>>>>>>>>>>刷新工作列表数据了>>>>>>>>>>总页数",
    state.userTotal_page
  );
  if (pageIdx < state.userTotal_page) {
    pageIdx++;
    let param = {
      openid: localStorage.getItem("openid"),
      page: pageIdx,
    };
    const res = await http.$get("/apies/backend/getUserList", param);
    if (res.code == 200) {
      state.userTotal = res.data.total;
      state.userTotal_page = res.data.total_page;
      let new_userName = [];
      let new_userUid = [];
      let nameUid = [];
      // 有分页数据,要追加数据
      let newUserList = [...state.userList, ...res.data.list];
      newUserList.map((i) => {
        new_userName.push(i.name);
        new_userUid.push(i.uid);
        nameUid.push({
          id: i.uid,
          name: i.name,
        });
      });
      state.userList = newUserList;   //页数追加重新刷新一下追加后的数据
      state.usersName = new_userName;
      state.userUid = new_userUid;
      state.new_nameUid = nameUid;
    } else {
      console.log(">>>>获取用户列表失败");
    }
  } else {
    ElMessage("没有数据了~~");
  }
};

// 获取运营人员名字和uid序号
const getUserList = async (pageId = 1) => {
  let param = {
    openid: localStorage.getItem("openid"),
    page: pageId,
  };
  const res = await http.$get("/apies/backend/getUserList", param);
  if (res.code == 200) {
    state.userTotal = res.data.total;
    state.userTotal_page = res.data.total_page;
    let new_userName = [];
    let new_userUid = [];
    let nameUid = [];
    // 有分页数据,要追加数据
    state.userList = res.data.list;
    res.data.list.map((i) => {
      new_userName.push(i.name);
      new_userUid.push(i.uid);
      nameUid.push({
        id: i.uid,
        name: i.name,
      });
    });
    state.usersName = new_userName;
    state.userUid = new_userUid;
    state.new_nameUid = nameUid;
  } else {
    console.log(">>>>获取用户列表失败");
  }
};

// 获取站点列表
const getSiteList = async (siteId, page = 1) => {
  const loadingInstance = ElLoading.service({
    text: `加载中...`,
   }) 
  let param = {
    openid: localStorage.getItem("openid"),
    sitetype: siteId,
    year: state.yearLevel,
    page: page,
  };
  const res = await http.$get("/apies/backend/getSiteList", param);
  if (res.code == 200) {
    console.log(">>>>>>>>>>>>>成功请求到站点数据了", res);
    let siteList = res.data.list;
    let newSiteList = [];
    state.total = res.data.total;
    state.total_page = res.data.total_page;
    siteList.map((i) => {
      // 工作流设置的要转多一步
      let workLineList_b = JSON.parse(JSON.stringify(state.workLineList))
      let workIdList_b = JSON.parse(JSON.stringify(state.workIdList))
      console.log(workLineList_b,'>>>>>>>>>>>所有选中的工作流',workIdList_b)
      let newLine_a = [];
      let getAllIdx = []
      workIdList_b.map((m, n) => {
        i.workitems.split(",").map((h, g) => {
          if (m == h) {
            getAllIdx.push(n)
          }
        })
      })
      console.log('>>>>>>>>>>当前选择项的下标', getAllIdx)
      workLineList_b.map((f, y) => {
        getAllIdx.map((i, k) => {
          if (y == i) {
            newLine_a.push(f);
          }
        })
      })
      console.log(newLine_a,'>>>>>>>>>>>>>>>>Site工作流显示数据列');


      // console.log(i.config_list.operator_id.split(","), ">>>>>>>路线工作流数组");
      let newLine = [];
      i.config_list.operator_id.split(",").map((i, k) => {
        state.userUid.map((j, y) => {
          if (Number(i) == j) {
            state.usersName.map((n, g) => {
              if (g == y) {
                newLine.push(n);
              }
            });
          }
        });
      });
      
      //这里接口返回的展具id,要转化成名称，同时ID也要传出去
      let newToolval = []
       state.toolArr.map((m, y) => {
        // let mArr = JSON.parse(JSON.stringify(m))
        console.log(m, '>>>>>展具id  Number(i.config_list.dev_id)') 
        if (m.value == Number(i.config_list.dev_id)) {
          newToolval.push(m.label)  
        }
      })
      console.log(newToolval[0] || "", '>>>>>>>>>>>>>>>')

      // console.log(newLine,'>>>>>>我是下标')
      // console.log(newLine);
      // 运营人员可能有多个，要用数组显示,暂时先不写
      newSiteList.push({
        sid: i.sid,
        siteTitle: i.name,
        logo: i.logo,
        logo_a: [i.logo],
        pathVal:i.sitetype_name,
        pathValId:i.tid,
        toolVal: newToolval[0] || i.config_list.dev_sn,  //展具值
        toolId: Number(i.config_list.dev_id),    //展具id
        exhibition: i.config_list.exhibition,
        buildtime1: i.config_list.buildtime1,
        buildtime2: i.config_list.buildtime2,
        ext_starttime: i.config_list.ext_starttime,
        ext_endtime: i.config_list.ext_endtime,
        finishtime1: i.config_list.finishtime1,
        finishtime2: i.config_list.finishtime2,
        city: i.config_list.city,
        province: i.config_list.province,
        positionimage: i.config_list.positionimage,
        positionimage_a: [i.config_list.positionimage],
        positionnum: i.config_list.positionnum,
        size: i.config_list.size,
        heightlimit: i.config_list.heightlimit,
        designimage: i.config_list.designimage,
        designimage_a: [i.config_list.designimage],
        exhcar: i.config_list.exhcar,
        tracar: i.config_list.tracar,
        operator_id: newLine, //运营人员列表
        operatorId_a: i.config_list.operator_id,
        controller: i.config_list.controller,
        sent_time: i.config_list.sent_time,   //邮件推送时间
        email_list: i.config_list.email_list,
        factory: i.config_list.factory,
        activity_name: i.config_list.activity_name,
        ext_starttime: i.config_list.ext_starttime,
        ext_endtime: i.config_list.ext_endtime,
        starttime: i.starttime,
        endtime: i.endtime,
        time_between: i.time_between,
        model: newLine_a, //工作流回显
        workitem: i.workitems,
        stage:
          i.stage == 1
            ? "制作中"
            : i.stage == 2
            ? "物流中"
            : i.stage == 3
            ? "搭建中"
            : i.stage == 4
            ? "运营中"
            : i.stage == 5
            ? "已结束"
            : i.stage == 6
            ? "暂无"
            : i.stage == 7
            ? "暂无"
            : "暂无",
      });
    });
    //----做数据追加开始----

    // 判断是否追加数据
    // let addtableDataLength = addtableData.length / 10
    // console.log(addtableDataLength, '>>>>>>>>>>>', page)
    // if (addtableDataLength < page) {
    //   addtableData = [...addtableData, ...newSiteList]
    //   console.log('>>>>>>>>>拿到表格数据', addtableData) 
    // }
    // state.tableData = addtableData; 

    // -----结束-----
    console.log('>>>>>>>>>拿到重组后的Site列表表格数据', newSiteList)

    state.tableData = newSiteList;

    loadingInstance.close()
  }
};

// 显示图表逻辑
const search = ref("");
const filterTableData = computed(() =>
  state.tableData.filter(
    (data) =>
      !search.value ||
      data.name.toLowerCase().includes(search.value.toLowerCase())
  )
);
// 编辑
const handleEdit = (index, row) => {
  pageIdx = 1;
  state.showModel = true;
  let editWorkRow = JSON.parse(JSON.stringify(row))
  // 获取当前的数据对象用于数据表单回显
  console.log('>>>>>>>>>>>>当前编辑的对象',editWorkRow);
  state.siteLineStr = editWorkRow.workitem  //初始化工作流
  state.siteVest_f = editWorkRow.model || []
  state.sid = editWorkRow.sid
  state.createName = editWorkRow.siteTitle
  state.pathVal = editWorkRow.pathVal
  state.buildtime1 = editWorkRow.buildtime1 
  state.buildtime2 = editWorkRow.buildtime2 
  state.finishtime1 = editWorkRow.finishtime1 
  state.finishtime2 = editWorkRow.finishtime2 
  state.ext_starttime = editWorkRow.ext_starttime 
  state.ext_endtime = editWorkRow.ext_endtime 
  state.factory = editWorkRow.factory
  state.controller = editWorkRow.controller
  state.sent_time = editWorkRow.sent_time || "22:00"
  state.email_list = editWorkRow.email_list 
  // state.worktype = editWorkRow.worktype 
  state.city = editWorkRow.city 
  state.province = editWorkRow.province 
  state.exhibition = editWorkRow.exhibition 
  state.positionnum = editWorkRow.positionnum 
  state.size = editWorkRow.size 
  state.heightlimit = editWorkRow.heightlimit 
  state.exhcar = editWorkRow.exhcar 
  state.tracar = editWorkRow.tracar 
  state.activity_name = editWorkRow.activity_name 

  // 展具值展具id
  state.toolSelVal = editWorkRow.toolId
  state.toolVal = editWorkRow.toolVal

  // 清空提交的数据参数
  state.pathValId = editWorkRow.pathValId       //路线id
  state.worktype = editWorkRow.operator_id
  state.operator_id = editWorkRow.operatorId_a

  // 用于上传图片回显用
  state.logoImg = [editWorkRow.logo_a[0]]
  state.positionimage = [editWorkRow.positionimage_a[0]]
  state.designimage = [editWorkRow.designimage_a[0]]
  
  state.uploadImgList = [{
    name: 'position.jpg',
    url: editWorkRow.positionimage
  }]
  state.uploadImgList_a = [{
    name: 'logo.jpg',
    url: editWorkRow.logo
  }]
  state.uploadImgList_b = [{
    name: 'design.jpg',
    url: editWorkRow.designimage
  }]
};
// 删除
const handleDelete = (index, row) => {
  console.log(index, row);
};

// 多选和单选的逻辑
const multipleTableRef = ref();
const multipleSelection = ref([]);
const handleSelectionChange = (val) => {
  multipleSelection.value = val;
  let selectionList = JSON.parse(JSON.stringify(val))
  state.selectReportlist = selectionList
  console.log(selectionList, ">>>>>>>>>>>所有选中项");
};

// 分页显示逻辑
// const currentPage4 = ref(1);    //当前页数
const pageSize4 = ref(10);
const small = ref(false);
const disabled = ref(false);

const handleSizeChange = (val) => {
  console.log(`${val} items per page`);
};
const handleCurrentChange = (val) => {
  console.log(`current page: ${val}`);
  // 这里调用翻页数据
  setTimeout(() => {
    getSiteList(state.sitetypeId, val);
  },500)
};

// 上传图片逻辑
// ---------------上传展位平面图的逻辑开始-------------
const beforeUpload = (file, uploadFile) => {
  console.log(">>>>>>>上传的图片数组", uploadFile);
  // 获取文件对象
  let isJPG;
  //判断图片类型
  if (
    file.type == "image/jpeg" ||
    file.type == "image/png" ||
    file.type == "image/JPG"
  ) {
    isJPG = true;
  } else {
    isJPG = false;
  }
  // 判断图片大小
  const isLt7M = file.size / 1024 / 1024 < 4; //上传文件小于4MB
  if (!isJPG) {
    ElMessage.error("图片建议是 JPG/PNG/JPEG 格式!");
    uploadFile.splice(uploadFile.indexOf(file), 1);
    return false;
  }
  if (!isLt7M) {
    ElMessage.error("图片大小不能超过 4MB!");
    uploadFile.splice(uploadFile.indexOf(file), 1);
    console.log(uploadFile, ">>>>>>>");
    return false;
  }
};
// 自定义上传图片逻辑
const selfUploadPic = (options) => {
  // 每次进来都清空一次
  state.positionimage = []
  let file = options.file;
  if (beforeUpload(file, state.uploadImgList) == undefined) {
    //图片文件转base64
    getBase64(file).then(async (res) => {
      //  console.log(JSON.parse(JSON.stringify(res)), ">>>>>>>>拿到图片base64图片格式了");
      //请求接口数据
      let newImgArr = [];
      const param = {
        openid: localStorage.getItem("openid"),
        img: JSON.parse(JSON.stringify(res)),
      };
      const resImg = await http.$post("/apies/uploadImage", param);
      if (resImg.code == 200) {
        newImgArr.push(resImg.data.img);
        console.log(newImgArr, ">>>>>>>>>>>>>>>>展位图片");
        state.positionimage = newImgArr;
        ElMessage({
          message: "展位图上传成功！",
          type: "success",
        });
      } else {
        ElMessage.error("上传失败请重新上传!");
      }
    });
  } else {
    console.log(">>>>>>>>>>>图片格式不正确");
  }
};
// 上传文件超出限制个数
const handleExceed = () => {
  ElMessage.error("已超过上传最大张数");
};

const handleRemove = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles);
};

const handlePictureCardPreview = (uploadFile) => {
  console.log(">>>>>>>>预览显示的图片", uploadFile.url);
  state.dialogImageUrl = uploadFile.url;
  state.dialogVisible = true;
};

// 图片文件转base64
const getBase64 = (file) => {
  // 直接将处理结果返回
  return new Promise((resolve, reject) => {
    let reader = new FileReader();
    let fileResult = "";
    reader.readAsDataURL(file);
    reader.onload = () => {
      fileResult = reader.result.toString();
    };
    reader.onerror = (error) => {
      reject(error);
    };
    reader.onloadend = () => {
      resolve(fileResult);
    };
  });
};

// ----------------结束-------------------

// ----------------上传logo图开始---------------------

// 自定义上传图片逻辑
const selfUploadPic_a = (options) => {
  // 清空数组
  state.logoImg = []
  let file = options.file;
  if (beforeUpload(file, state.uploadImgList_a) == undefined) {
    //图片文件转base64
    getBase64(file).then(async (res) => {
      //  console.log(JSON.parse(JSON.stringify(res)), ">>>>>>>>拿到图片base64图片格式了");
      //请求接口数据
      let newImgArr = [];
      const param = {
        openid: localStorage.getItem("openid"),
        img: JSON.parse(JSON.stringify(res)),
      };
      const resImg = await http.$post("/apies/uploadImage", param);
      if (resImg.code == 200) {
        console.log(resImg.data, ">>>>>>>>>>>>>>>>上传成功了");
        newImgArr.push(resImg.data.img);
        // 需要提交logo的图片路径
        console.log(">>>>>>>>>>>>>>logo", newImgArr);
        state.logoImg = newImgArr;
        ElMessage({
          message: "LOGO图上传成功！",
          type: "success",
        });
      } else {
        ElMessage.error("上传失败请重新上传!");
      }
    });
  } else {
    console.log(">>>>>>>>>>>图片格式不正确");
  }
};
// 上传文件超出限制个数
const handleExceed_a = () => {
  ElMessage.error("已超过上传最大张数");
};

const handleRemove_a = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles);
};

const handlePictureCardPreview_a = (uploadFile) => {
  console.log(">>>>>>>>预览显示的图片", uploadFile.url);
  state.dialogImageUrl_a = uploadFile.url;
  state.dialogVisible_a = true;
};

// ----------------------结束----------------------

// ----------------------上传展具开始-------------------------

// 自定义上传图片逻辑
const selfUploadPic_b = (options) => {
  state.designimage = []
  let file = options.file;
  if (beforeUpload(file, state.uploadImgList_a) == undefined) {
    //图片文件转base64
    getBase64(file).then(async (res) => {
      //  console.log(JSON.parse(JSON.stringify(res)), ">>>>>>>>拿到图片base64图片格式了");
      //请求接口数据
      let newImgArr = [];
      const param = {
        openid: localStorage.getItem("openid"),
        img: JSON.parse(JSON.stringify(res)),
      };
      const resImg = await http.$post("/apies/uploadImage", param);
      if (resImg.code == 200) {
        newImgArr.push(resImg.data.img);
        console.log(newImgArr, ">>>>>>>>>>>>>>>>上传展具图片");
        state.designimage = newImgArr;
        ElMessage({
          message: "展具上传成功！",
          type: "success",
        });
      } else {
        ElMessage.error("上传失败请重新上传!");
      }
    });
  } else {
    console.log(">>>>>>>>>>>图片格式不正确");
  }
};
// 上传文件超出限制个数
const handleExceed_b = () => {
  ElMessage.error("已超过上传最大张数");
};

const handleRemove_b = (uploadFile, uploadFiles) => {
  console.log(uploadFile, uploadFiles);
};

const handlePictureCardPreview_b = (uploadFile) => {
  console.log(">>>>>>>>预览显示的图片", uploadFile.url);
  state.dialogImageUrl_b = uploadFile.url;
  state.dialogVisible_b = true;
};

// -------------------------结束-------------------------

const changeYear = (e) => {
  console.log('>>>>>>>>>>??????选中年份了', e)
  state.yearLevel = e
  localStorage.setItem('yearLevel', e);
};

// 查询
const checkSiteList = () => {
  if(state.yearLevel == "") {
    ElMessage({
      message: '请选择年份',
      type: 'warning',
    })
    return
  }
  console.log(">>>>>>查询年份数据", state.yearLevel);
  addtableData = []
  getSiteList(state.sitetypeId);
};
// 清除
const clearSite = () => {
  console.log(">>>>>>根据id进行清除");
};
// 增加
const addSite = () => {
  console.log(">>>>>>>>>>增加站点数据");
  pageIdx = 1;
  state.sid = ""
  clearAllForm()
  state.showModel = true;
};
// 取消表单
const closeInput = () => {
  state.showModel = false;
};

// 清空表单所有数据
const clearAllForm = () => {
  state.siteLineStr = "" ,  //工作流参数
  state.siteVest_f = [],
  state.createName = "",
  state.pathVal = "",
  state.buildtime1 = "",  
  state.buildtime2 = "",
  state.finishtime1 = "", 
  state.finishtime2 = "", 
  state.ext_starttime = "", 
  state.ext_endtime = "", 
  state.factory = "",
  state.controller = "", 
  state.sent_time = "22:00"
  state.email_list = "",
  state.worktype = [], 
  state.city = "", 
  state.province = "", 
  state.exhibition = "", 
  state.positionnum = "", 
  state.size = "", 
  state.heightlimit = "","",
  state.exhcar = "", 
  state.tracar = "", 
  state.activity_name = "", 
  state.toolSelVal = "",   //清空展具值和展具id
  state.toolVal = "",

  // 清空提交的数据参数
  state.pathValId = "",       //路线id
  state.operator_id = "",

  //编辑原本有的三张图片
  state.logoImg = [],
  state.positionimage = [],
  state.designimage = []

  state.uploadImgList = []
  state.uploadImgList_a = []
  state.uploadImgList_b = []
};

// 非空判断
const isKongForm = () => {
  console.log(!(state.buildtime2 !== null))
  // debugger
  if (state.createName == "" || 
      state.pathVal == "" || 
      state.toolVal == "" ||
      !(state.buildtime1 !== null) || 
      !(state.buildtime2 !== null) || 
      !(state.finishtime1 !== null) || 
      !(state.finishtime2 !== null) || 
      !(state.ext_starttime !== null) ||
      !(state.ext_endtime !== null) ||
      state.factory == "" ||
      state.controller == "" ||
      state.email_list == undefined  ||
      state.worktype == "" ||
      state.city == "" ||
      state.province == "" ||
      state.exhibition == "" ||
      state.positionnum == "" ||
      state.size == "" ||
      state.heightlimit == "" ||
      state.exhcar == "" ||
      state.tracar == "" ||
      state.activity_name == "" ||
      state.uploadImgList.length == 0 ||
      state.uploadImgList_a.length == 0 ||
      state.uploadImgList_b.length == 0 || 
      state.siteVest_f.length == 0
      ) {
        return false
  } else {
    return true
  }
};

// 确认表单
const startSubmit = async () => {
  // if (isKongForm()) {
  if (true) {
  // if (state.logoImg.length == 0) {
  //   ElMessage({
  //     message: 'logo图片正在上传中，请稍等...',
  //     type: 'warning',
  //   })
  //   return
  // }
  // if (state.positionimage.length == 0) {
  //   ElMessage({
  //     message: '展位图正在上传中，请稍等...',
  //     type: 'warning',
  //   })
  //   return
  // }
  // if (state.designimage.length == 0) {
  //   ElMessage({
  //     message: '展具图正在上传中，请稍等...',
  //     type: 'warning',
  //   })
  //   return
  // }
  let new_logoImg = JSON.parse(JSON.stringify(state.logoImg))
  let new_positionimage = JSON.parse(JSON.stringify(state.positionimage))
  let new_designimage = JSON.parse(JSON.stringify(state.designimage))
  let sid_a = state.sid == "" ? 0 : state.sid
  let params = {
    sid: sid_a,
    openid: localStorage.getItem("openid"),
    name: state.createName,
    logo: new_logoImg[0], //logo图片
    sitetype_name: state.pathVal, //路线名称
    sitetype: state.pathValId, //路线Id
    buildtime1: state.buildtime1,
    buildtime2: state.buildtime2,
    finishtime1: state.finishtime1,
    finishtime2: state.finishtime2,
    ext_starttime: state.ext_starttime,
    ext_endtime: state.ext_endtime,
    factory: state.factory || "-",
    controller: state.controller,
    sent_time: state.sent_time,
    email_list: state.email_list,
    operator_id: state.operator_id, //运营账号id,用，拼接成字符串
    city: state.city,
    province: state.province,
    exhibition: state.exhibition,
    positionimage: new_positionimage[0], //展位图片
    positionnum: state.positionnum,
    size: state.size,
    heightlimit: state.heightlimit,
    designimage: new_designimage[0], //展具图
    dev_id: state.toolSelVal,   //展具ID
    exhcar: state.exhcar,
    tracar: state.tracar,
    activity_name: state.activity_name,
    radioState: state.radioState == "启用" ? 1 : state.radioState == "停用" ? 0 : '',
    workitems: state.siteLineStr,
  };
  console.log(">>>>>>>>>>>>>需要提交的数据", params);
  const res = await http.$post("/apies/backend/editSite", params);
  if (res.code == 200) {
    addtableData = []
    getSiteList(state.sitetypeId);
    state.currentPage4 = 1
    state.showModel = false
    state.sid == "" ? ElMessage({
        message: '创建成功',
        type: 'success',
      }) : ElMessage({
        message: '编辑成功',
        type: 'success', 
      })
  } else {
    state.wid == "" ? ElMessage('创建失败！') : ElMessage('编辑失败！')
    state.showModel = false;
  }
  } else {
    ElMessage('填空项不能为空!')
  }
};

//报告导出
const reportExport = async () => {
  let newselectReportlist = JSON.parse(JSON.stringify(state.selectReportlist))
  if (newselectReportlist != "") {
    //判断所有选中的站点是否已经结束了
    let isReportend = newselectReportlist.every(i => {
      return i.stage == '已结束'
    })
    // 过滤出不是已结束的站点数据
    let noEndReport = newselectReportlist.filter(j => j.stage != '已结束')
    let siteNames = noEndReport.map((user) => {
        return user.siteTitle + '站' + '  '
      }).join(',')
    console.log('>>>>>>>>>>没结束的站点', siteNames)

    if (isReportend) {
      let siteIdStr = newselectReportlist.map((item) => {
        return item.sid
      }).join(',')
      console.log('>>>>>>>>>>>>字符串站点数据', siteIdStr)
       let paramsData = {
           openid: localStorage.getItem("openid"),
           site_id_str: siteIdStr
      };
      window.location.href = `https://platform.easys.co/apies/backend/excelData?site_id_str=${siteIdStr}&openid=${localStorage.getItem("openid")}`
    } else {
      ElMessage(`${siteNames}还未结束!`)
    }
  } else {
    ElMessage('请选择要导出的报告!')
  }
}
</script>
  
  <style scoped>
.Title {
  font-weight: 600;
  font-size: 20px;
  margin-bottom: 20px;
}

.flewbtn {
  display: flex;
  align-items: center;
  margin-bottom: 20px;
}

.elSelect_a {
  border-radius: 15px;
  width: 250px;
  margin-right: 15px;
}
::v-deep .elSelect_a .el-input__wrapper {
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  box-sizing: border-box;
  box-shadow: none;
}
.elSelect_y {
  border-radius: 15px;
  width: 160px;
  margin-left: 350px;
}
::v-deep .elSelect_y .el-input__wrapper {
  background-color: #e8e8e8;
  border-color: #409eff;
  box-sizing: border-box;
  box-shadow: none;
}

.elSelect {
  border-radius: 15px;
  width: 250px;
  /* height: 28px; */
  flex: 8;
}
::v-deep .elSelect .el-input__wrapper {
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  box-sizing: border-box;
  box-shadow: none;
}

::v-deep .elSelect .el-input__wrapper:focus {
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  box-sizing: border-box;
  box-shadow: none;
  color: #c0c4cc;
}

::v-deep .elSelect .el-input__inner {
  padding: 0;
  margin: 0;
  box-sizing: border-box;
  box-shadow: none;
  padding: 0;
}

/* 改变输入框样式 */
::v-deep .enterpriseName .el-input__inner {
  /* width:100%; */
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  color: #000;
  padding: 10px;
  box-sizing: border-box;
  /* border-radius: 5px; */
  height: 25px;
  border-radius: 3px;
}

.enterpriseName ::v-deep .el-input__inner {
  border: none;
}

::v-deep .enterpriseName .el-input__wrapper {
  padding: 0;
}

/* 改变上传按钮样式 */
::v-deep.el-upload--picture-card,
::v-deep .el-upload-list__item {
  width: 100px;
  height: 100px;
  line-height: 110px;
  border: none;
  background: #fff;
}

/* 改变选择器样式 */
::v-deep .Selectbox .el-input__wrapper {
  /* width:100%; */
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  color: #000;
  padding: 10px;
  box-sizing: border-box;
  /* border-radius: 5px; */
  height: 28px;
  width: 100% !important;
  flex: 8;
}
::v-deep .Selectbox .el-input__wrapper .el-input__inner {
  border: none;
}
/* 改变文本域样式 */
::v-deep .textTip .el-textarea__inner {
  background-color: #e8e8e8;
  border-color: #c0c4cc;
  color: #000;
  padding: 10px;
  box-sizing: border-box;
}

.block-col-2 .demonstration {
  display: block;
  color: var(--el-text-color-secondary);
  font-size: 14px;
  margin-bottom: 20px;
}

/* 隐藏横向滚动条 */
.el-scrollbar__bar {
  display: none !important;
}

#el-id-878-3 .el-dialog__body {
  padding: 0 !important;
}

/* 改变上传框框的大小 */
::v-deep .el-upload--picture-card {
  border: 1px dashed #e7e7e9;
}
::v-deep .el-upload--picture-card:hover {
  border-color: #e7e7e9;
  color: #e7e7e9;
}
::v-deep .el-upload--picture-card {
  width: 70px;
  height: 70px;
  font-size: 16px !important;
}
::v-deep .el-upload {
  width: 70px;
  height: 70px;
  line-height: 50px;
  font-size: 16px;
}
::v-deep .el-upload-list--picture-card .el-upload-list__item {
  width: 70px;
  height: 70px;
  line-height: 50px;
  font-size: 16px;
}

::v-deep .el-upload-list--picture-card .el-upload-list__item-actions:hover {
  opacity: 1;
  font-size: 16px;
}

::v-deep .el-upload-list--picture-card .el-upload-list__item-thumbnail {
  width: 70px;
  height: 70px;
  line-height: 50px;
  font-size: 16px;
}
::v-deep .el-upload--picture-card .el-icon-plus {
  width: 28px;
  height: 28px !important;
  line-height: 1.7 !important;
}
::v-deep .avatar {
  width: 70px;
  height: 70px;
}

/* 确认按钮样式 */
.dialog-footer {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 40px;
}
.dialog-footer_a {
  width: 100%;
  display: flex;
  justify-content: flex-end;
  margin-top: 10px;
}

::v-deep(
    .el-pagination.is-background .el-pager li:not(.is-disabled).is-active
  ) {
  background-color: #409eff !important;
}

.siteAll {
  /* flex: 2; */
  line-height: 20px;
  text-align: center;
  font-weight: 600;
  margin-left: 28px;
  margin-right: 6px;
}
.siteAll_a {
  /* flex: 2; */
  line-height: 22px;
  text-align: center;
  width: 107px;
  font-weight: 600;
  margin-right: 7px;
}
.siteAll_a_1 {
  line-height: 22px;
  text-align: center;
  width: 107px;
  font-weight: 600;
  margin-left: 3px; 
  margin-right: -19px;
}

.siteAll_b {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 8px;
}
.siteAll_c {
  /* flex: 2; */
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 43px;
  margin-right: 7px;
}
.siteAll_c1 {
  /* flex: 2; */
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 1px;
  margin-right: 7px;
}
.siteAll_d {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 5px;
}
.siteAll_e {
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 42px;
  margin-right: 5px;
}
.siteAll_e1 {
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 55px;
  margin-right: 8px;
}
.siteAll_e2 {
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 28px;
  margin-right: 6px;
}
.siteAll_f {
  margin: 20px 7px 18px 14px;
  font-weight: 600;
  width: 90px;
  text-align: end;
}
.siteAll_g {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 3px;
}
.siteAll_h {
  /* flex: 2; */
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 26px;
  margin-right: 7px;
}
.siteAll_h1 {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-top: 0px;
}
.siteAll_h2 {
  /* flex: 2; */
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 1px;
  margin-right: 7px;
}
.siteAll_h5 {
  /* flex: 2; */
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 27px;
  margin-right: 7px;
}

.siteAll_h3 {
  /* flex: 2; */
  line-height: 22px;
  text-align: center;
  width: 78px;
  font-weight: 600;
  margin-left: 18px;
  margin-right: -4px;
}
.siteAll_h4 {
  margin: 19px 6px 23px 14px;
  font-weight: 600;
  width: 90px;
  text-align: end;
  display: flex;
}
.siteAll_h5 {
  font-weight: 600;
  display: flex;
  justify-content: center;
  margin-top: 5px;
  margin-right: 8px;
  margin-left: 28px;
}
.siteAll_h7 {
  line-height: 38px;
  text-align: center;
  font-weight: 600;
  margin-left: 27px;
  margin-right: 7px;
}
.siteAll_h6 {
  flex: 8;
  background-color: #e8e8e8;
  padding-left: 8px;
  /* padding-top: 3px; */
  border-radius: 3px;
  box-sizing: border-box;
  margin-top: 5px;
}

.line_b {
  font-weight: 600;
  display: flex;
  justify-content: center;
  margin-top: 7px;
  margin-left: 11px;
  margin-right: 12px;
}
.line_b1 {
  font-weight: 600;
  box-sizing: border-box;
  padding: 0 0 0 13px;
}

.line_f {
  flex: 8;
  background-color: #e8e8e8;
  padding-left: 6px;
  border-radius: 3px;
  box-sizing: border-box;
}

.checkman {
  width: 100%;
  display: flex;
  justify-content: center;
  margin-top: 20px;
}

.line_g_a {
  flex: 2;
  line-height: 37px;
  text-align: right;
  font-weight: 600;
  padding-right: 5px;
}
</style>
  